package net.fdukedom.epicurus.pm.actions;

import net.fdukedom.epicurus.presentation.actions.AbstractAction;
import net.fdukedom.epicurus.presentation.SessionData;
import net.fdukedom.epicurus.pm.domain.entity.PrivateMessage;
import net.fdukedom.epicurus.pm.domain.util.PrivateMessageHelper;
import net.fdukedom.epicurus.domain.entity.User;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Dmitry Y. Kochelaev
 */
public class InboxAction extends AbstractAction {

    private PrivateMessageHelper privateMessageHelper = PrivateMessageHelper.getInstance();

    protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        User user = SessionData.getInstance(request).getUser();
        List<PrivateMessage> messages = privateMessageHelper.findByRecepient(user);
        request.setAttribute("messages", messages);
        return mapping.findForward("success");
    }
}
